#include "sw_input_manager.h"
#include "sw_game_state.h"
#include "sw_game_state_skateboard.h"
#include "sw_game_state_main.h"
#include <allegro5\allegro_primitives.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include "globals.h"

#include "sw_game_state_menu.h"

sw_game_state_menu::sw_game_state_menu() {
	select_skate = false;
	font = al_load_font("fonts/arial.ttf", 36, 0);
}

sw_game_state_menu::~sw_game_state_menu() {
	al_destroy_font(font);
}

void sw_game_state_menu::draw_on_screen() {
	int ty = select_skate ? 260 : 200;
	al_draw_filled_triangle(200, ty, 200, ty+40, 240, ty+20, al_map_rgb(0, 255, 255));
	al_draw_text(font, al_map_rgb(255, 255, 255), 250, 260, 0, "Skateboard");
	al_draw_text(font, al_map_rgb(255, 255, 255), 250, 200, 0, "Main game (currently a mess)");
}

void sw_game_state_menu::compute_timestep() {
	for (int i=0; i<global_input_manager->times_pressed(ALLEGRO_KEY_UP)+global_input_manager->times_pressed(ALLEGRO_KEY_DOWN); i++) {
		select_skate = !select_skate;
	}
	if (global_input_manager->times_pressed(ALLEGRO_KEY_SPACE)>0) {
		if (select_skate) {
			sw_game_state_skateboard* sub = new sw_game_state_skateboard();
			global_game_state->set_game_state_sub(sub);
		} else {
			sw_game_state_main* sub = new sw_game_state_main();
			global_game_state->set_game_state_sub(sub);
		}
		// reset it just for the hell of it
		select_skate = true;
	}
}